package com.jixiang.dictionary.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jixiang.model.common.dtos.ResponseResult;
import com.jixiang.model.dictionary.entity.DsLayoutImg;
import com.jixiang.dictionary.service.DsLayoutImgService;
import com.jixiang.utils.thread.UserThread;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import static com.jixiang.common.constants.RedisConstants.REDIS_PREX_DSLAYOUTIMG;

/**
 * (DsLayoutImg)表控制层
 *
 * @author makejava
 * @since 2023-10-17 00:19:49
 */
@RestController
@RequestMapping("dsLayoutImg")
public class DsLayoutImgController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private DsLayoutImgService dsLayoutImgService;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @ApiOperation("管理端用户添加购物页首页图片")
    @PostMapping("/addLayoutCarousel")
    public ResponseResult addLayoutCarousel(@RequestBody(required = false)DsLayoutImg dsLayoutImg)  {
        stringRedisTemplate.delete(REDIS_PREX_DSLAYOUTIMG);
        dsLayoutImg.setCreateUserId(UserThread.getUser().getId());
        dsLayoutImgService.save(dsLayoutImg);
        stringRedisTemplate.delete(REDIS_PREX_DSLAYOUTIMG);
        return ResponseResult.okResult("添加成功");
    }


    @ApiOperation("管理端用户获取购物页首页图片")
    @GetMapping("/getLayoutCarouselList")
    public ResponseResult addLayoutCarousel()  {
        List<DsLayoutImg> list = dsLayoutImgService.query().orderByAsc("priority").list();
        return ResponseResult.okResult(list);
    }

    @ApiOperation("管理端用户删除购物页首页图片")
    @DeleteMapping("/delLayoutCarouseById")
    public ResponseResult delLayoutCarouseById(@RequestParam(required = true,value = "id")String id)  {
        stringRedisTemplate.delete(REDIS_PREX_DSLAYOUTIMG);
        dsLayoutImgService.removeById(id);
        stringRedisTemplate.delete(REDIS_PREX_DSLAYOUTIMG);
        return ResponseResult.okResult("删除成功");
    }

    @ApiOperation("用户获取购物页首页图片")
    @GetMapping("/appGetLayoutCarouselList")
    public ResponseResult appGetLayoutCarouselList()  {
        return dsLayoutImgService.appGetLayoutCarouselList();
    }

}

